package com.nuoniu.sibanyun.controller.erp;

import com.alibaba.fastjson.JSONObject;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.ErpPeriodSaveDto;
import com.nuoniu.sibanyun.service.erp.IErpPeriodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author zy
 * @version1.0
 * @Date: 2023/01/13 22:10
 */
@RestController
@RequestMapping("/erp/settleAccounts")
@Api(value = "业务结账", tags = "业务结账")
public class BusinessPeriodClosedController extends BaseController {
    @Autowired
    private IErpPeriodService erpPeriodService;

    @ApiOperation("业务期末记账")
    @RequestMapping("/postSettleSave")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginDate", value = "开始日期"),
            @ApiImplicitParam(name = "endDate", value = "结束日期"),
            @ApiImplicitParam(name = "status", value = "状态0反结 1结")})

    public HttpResult settleAccounts(@RequestBody String params) {
        JSONObject jsonObject = JSONObject.parseObject(params);
        String beginDate = jsonObject.getString("beginDate");
        String endDate = jsonObject.getString("endDate");
        Integer status = jsonObject.getInteger("status");
        if (beginDate.equals("") || endDate.equals("")) {
            throw new NuoNiuException("数据异常");
        }
        erpPeriodService.BusinessSettleAccounts(beginDate, endDate, status);
        return HttpResult.ok();
    }
}